//---------------------------------------------------------------------------
//	Greenplum Database
//	Copyright (C) 2012 EMC Greenplum
//
//	@filename:
//		COptColInfo.h
//
//	@doc:
//		Class to uniquely identify a column in optimizer
//
//	@test:
//
//
//---------------------------------------------------------------------------

#ifndef SPQDXL_COptColInfo_H
#define SPQDXL_COptColInfo_H

#include "spqos/base.h"
#include "spqos/common/CRefCount.h"
#include "spqos/utils.h"

namespace spqdxl
{
using namespace spqos;

//---------------------------------------------------------------------------
//	@class:
//		COptColInfo
//
//	@doc:
//		pair of column id and column name
//
//---------------------------------------------------------------------------
class COptColInfo : public CRefCount
{
private:
	// column id
	ULONG m_colid;

	// column name
	CWStringBase *m_str;

	// private copy c'tor
	COptColInfo(const COptColInfo &);

public:
	// ctor
	COptColInfo(ULONG colid, CWStringBase *str) : m_colid(colid), m_str(str)
	{
		SPQOS_ASSERT(m_str);
	}

	// dtor
	virtual ~COptColInfo()
	{
		SPQOS_DELETE(m_str);
	}

	// accessors
	ULONG
	GetColId() const
	{
		return m_colid;
	}

	CWStringBase *
	GetOptColName() const
	{
		return m_str;
	}

	// equality check
	BOOL
	Equals(const COptColInfo &optcolinfo) const
	{
		// don't need to check name as column id is unique
		return m_colid == optcolinfo.m_colid;
	}

	// hash value
	ULONG
	HashValue() const
	{
		return spqos::HashValue(&m_colid);
	}
};

// hash function
inline ULONG
UlHashOptColInfo(const COptColInfo *opt_col_info)
{
	SPQOS_ASSERT(NULL != opt_col_info);
	return opt_col_info->HashValue();
}

// equality function
inline BOOL
FEqualOptColInfo(const COptColInfo *opt_col_infoA,
				 const COptColInfo *opt_col_infoB)
{
	SPQOS_ASSERT(NULL != opt_col_infoA && NULL != opt_col_infoB);
	return opt_col_infoA->Equals(*opt_col_infoB);
}

}  // namespace spqdxl

#endif	// !SPQDXL_COptColInfo_H

// EOF
